﻿
CREATE FUNCTION [dbo].[NormalizeHour]( @TheDate smalldatetime) 
RETURNS smalldatetime
AS
BEGIN
	DECLARE @datNowDate smalldatetime, @fltDateConverted float, @intDays int, @fltTimePart float

	IF @TheDate IS NULL SET @TheDate = GETDATE()

	SET @fltDateConverted = cast(@TheDate as float) 
	SET @intDays = FLOOR(@fltDateConverted)
	SET @fltTimePart = @fltDateConverted - @intDays

	SET @datNowDate = cast( @intDays + FLOOR( @fltTimePart / 0.0416666666666667 ) * 0.0416666666666667 as smalldatetime)

	RETURN @datNowDate
END
